<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>个人信息修改</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/loading.css" rel="stylesheet" />
		<style>
			.area {
				margin: 20px auto 0px auto;
			}
			.mui-input-group:first-child {
				margin-top: 20px;
			}
			.mui-input-group label {
				width: 22%;
			}
			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 78%;
			}
			.mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 6px;
			}
			.mui-content-padded {
				margin-top: 25px;
			}
			.mui-btn {
				padding: 10px;
			}
			.mui-title{
				text-align: right;
			}
			
			.mui-bar .mui-title{
				right:18px;
			}
			
		</style>
	</head>

	<body>
			<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">修改</h1>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded" style="text-align: center;">
				<img width="100px" src="images/user-photo.png" height="100px"/>
				<h3>您好</h1>
			</div>
			<form  id="userForm" class="mui-input-group" action="" method="post">
				<div class="mui-input-row">
					<label>昵称<span style="color:red">*</span></label>
					<input id='nickname' name="nickname" type="text" class="mui-input-clear mui-input" placeholder="请输入用户名">
				</div>
				<div class="mui-input-row">
					<label>密码<span style="color:red">*</span></label>
					<input id='password' name="password" type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
				</div>
				<div class="mui-input-row">
					<label>姓名</label>
					<input id='username' name="username" type="text" class="mui-input-clear mui-input" placeholder="请输入真实姓名">
				</div>
				<div class="mui-input-row">
					<label>手机<span style="color:red">*</span></label>
					<input id='phone' name="phone" type="number" class="mui-input-clear mui-input" placeholder="请输联系方式">
				</div>
				<div class="mui-input-row">
					<label>邮箱<span style="color:red">*</span></label>
					<input id='email' name="email"  type="email" class="mui-input-clear mui-input" placeholder="请输入邮箱">
				</div>
				<div class="mui-input-row">
					<label>微信</label>
					<input id='wechat' name="wechat"  type="email" class="mui-input-clear mui-input" placeholder="请输入微信">
				</div>
				<div class="mui-input-row">
					<label>QQ</label>
					<input id='qq' name="qq" type="number" class="mui-input-clear mui-input" placeholder="请输入QQ">
				</div>
			</form>
			<div class="mui-content-padded">
			<button id='reg' class="mui-btn mui-btn-block mui-btn-primary">提交编辑</button>
			</div>
			<div class="mui-content-padded">
				<div id="bottom" style="text-align: center;  position:absolute; bottom:0;width:100%; height: 30px;">
					<p>(c) Copyright 2018 maxun.xyz. All Rights Reserved.</p>
				</div>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/app.js"></script>
		<script>
			(function($, doc) {
				$.init();
				$.plusReady(function() {
					var settings = app.getSettings();
					var regButton = doc.getElementById('reg');
					var accountBox = doc.getElementById('account');
					var passwordBox = doc.getElementById('password');
					var passwordConfirmBox = doc.getElementById('password_confirm');
					var emailBox = doc.getElementById('email');
					regButton.addEventListener('tap', function(event) {
						var regInfo = {
							account: accountBox.value,
							password: passwordBox.value,
							email: emailBox.value
						};
						var passwordConfirm = passwordConfirmBox.value;
						if (passwordConfirm != regInfo.password) {
							plus.nativeUI.toast('密码两次输入不一致');
							return;
						}
						app.reg(regInfo, function(err) {
							if (err) {
								plus.nativeUI.toast(err);
								return;
							}
							plus.nativeUI.toast('注册成功');
							/*
							 * 注意：
							 * 1、因本示例应用启动页就是登录页面，因此注册成功后，直接显示登录页即可；
							 * 2、如果真实案例中，启动页不是登录页，则需修改，使用mui.openWindow打开真实的登录页面
							 */
							plus.webview.getLaunchWebview().show("pop-in",200,function () {
								plus.webview.currentWebview().close("none");
							});
							//若启动页不是登录页，则需通过如下方式打开登录页
//							$.openWindow({
//								url: 'login.html',
//								id: 'login',
//								show: {
//									aniShow: 'pop-in'
//								}
//							});
						});
					});
				});
			}(mui, document));
		</script>
			<script src="js/jquery-1.8.3.js"></script>
			<script src="js/loading.js"></script>
			<script>
                $("#reg").click(function () {
                    var check=true;
                    mui("#userForm input").each(function() {
                        //若当前input为空，则alert提醒
                        if(this.name!="username"&&this.name!="wechat"&&this.name!="qq"){
                            if(!this.value || this.value.trim() == "") {
                                var label = this.previousElementSibling;
                                mui.alert(label.innerText.replace("*","") + "不允许为空");
                                check = false;
                                return false;
                            }
                        }

                    }); //校验通过，继续执行业务逻辑
                    if(check){
                        $.ajax({
                            type:'get',
                            url:'../controller/UserController.php',
                            data:{
                                nickname:$("#nickname").val(),username:$("#username").val(),phone:$("#phone").val()
                                ,email:$("#email").val(),wechat:$("#wechat").val(),qq:$("#qq").val(),password:$("#password").val(),
                                codeId:getUrlParam("codeId"),action:'saveEdit',id:getUrlParam("id")
                            },
                            cache:false,
                            dataType:'json',
                            success:function(data){
                            if(data.message=="success"){
                                mui.alert("数据更新成功！");
                                window.location.href="main.html?id="+getUrlParam("id");
							}else{
                                mui.alert("更新失败，请返回重试！");
							}
                            }
                        });
                    }
                });

                //获取url中的参数
                function getUrlParam(name) {
                    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
                    var r = window.location.search.substr(1).match(reg); //匹配目标参数
                    if (r != null) return unescape(r[2]); return null; //返回参数值
                }
                $(function () {
                    mui.showLoading("正在加载..","div");
                    $.ajax({
                        type:'get',
                        url:'../controller/UserController.php',
                        data:{
                            action:'toEdit',
							id:getUrlParam('id')
                        },
                        cache:false,
                        dataType:'json',
                        success:function(data){
                            console.log(data)
                            $("#nickname").val(data[0].nick_name);
                            $("#username").val(data[0].really_name);
                            $("#phone").val(data[0].phone);
                            $("#email").val(data[0].email);
                            $("#wechat").val(data[0].wechat);
                            $("#qq").val(data[0].qq);
                            $("#password").val("*****");
                            mui.hideLoading();
                        }
                    });
                })
                $(window).resize(function(){
                    var h_doc = $(document).height();
                    var h_foo = h_doc-25;
                    $('#bottom').offset({top:h_foo,left:0});
                });
			</script>
			<script src="https://s13.cnzz.com/z_stat.php?id=1273362290&web_id=1273362290" language="JavaScript"></script>
	</body>

</html>